home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / xlib06p1.zip / DEMO1.CPP < prev    next >
C/C++ Source or Header  |  1995-03-05  |  22KB  |  581 lines

  1. /* VERY QUICK AND ULTRA-DIRTY DEMO USING XLIB */
  2.  
  3. /* Simple Demo of MODE X Split screen and panning  */
  4. /* Compile using Turbo C and Tasm                  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <ctype.h>
  10. #include <dos.h>
  11. #include <mem.h>
  12. #include "Xlib_all.h"
  13.  
  14. #define MAX_OBJECTS  10
  15.  
  16. static char *texttest[6] =
  17.  {"This is a demonstration of the fonts ",
  18.   "available in XLIB. Notice fixed and  ",
  19.   "variabe spaced fonts are supported but",
  20.   "are limited to a maximum of 8 pixels in",
  21.   "width. Height of the characters is    ",
  22.   "ofcourse unlimited..."};
  23.  
  24. typedef struct {
  25.    int X,Y,Width,Height,XDir,YDir,XOtherPage,YOtherPage;
  26.    BYTE * Image;
  27.    BYTE * bg;
  28.    BYTE * bgOtherPage;
  29. } AnimatedObject;
  30.  
  31. AnimatedObject objects[MAX_OBJECTS];
  32. int object_count=0;
  33.  
  34. static BYTE  bm[] = {4,12,
  35.   /* plane 0 */
  36.   2,2,2,2,2,1,1,1,2,1,1,1,2,3,3,1,
  37.   2,0,0,3,2,0,0,3,2,0,0,3,2,0,0,3,
  38.   2,3,3,1,2,1,1,1,2,1,1,1,2,2,2,2,
  39.   /* plane 1 */
  40.   2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1,
  41.   1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,
  42.   1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2,
  43.   /* plane 2 */
  44.   2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1,
  45.   1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,
  46.   1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2,
  47.   /* plane 3 */
  48.   2,2,2,2,1,1,1,2,1,1,1,2,1,3,3,2,
  49.   3,0,0,2,3,0,0,2,3,0,0,2,3,0,0,2,
  50.   1,3,3,2,1,1,1,2,1,1,1,2,2,2,2,2};
  51.  
  52. static BYTE  bm2[] = {4,12,
  53.    /* plane 0 */
  54.    2,2,2,2,2,4,4,4,2,4,4,4,2,2,2,4,
  55.    2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2,
  56.    2,2,2,4,2,4,4,4,2,4,4,4,2,2,2,2,
  57.    /* plane 1 */
  58.    2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4,
  59.    4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4,
  60.    4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2,
  61.    /* plane 2 */
  62.    2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4,
  63.    4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4,
  64.    4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2,
  65.    /* plane 2 */
  66.    2,2,2,2,4,4,4,2,4,4,4,2,4,2,2,2,
  67.    2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2,
  68.    4,2,2,2,4,4,4,2,4,4,4,2,2,2,2,2};
  69.  
  70. int textwindow_x=0,textwindow_y=0;
  71. BYTE * pal;
  72. BYTE * pal2;
  73. char palscrolldir=1;
  74. BYTE * userfnt1;
  75.  
  76.  
  77.  
  78. void drawtext(int height){
  79.   int i;
  80.   for (i=0;i<6;i++)
  81.     x_printf(textwindow_x+5,50+i*(height+2),VisiblePageOffs,9,texttest[i]);
  82. }
  83.  
  84. /* initialize a new object */
  85. void init_object(int x,int y,int width, int height, int xdir, int ydir,
  86.   BYTE * image){
  87.   int i;
  88.   objects[object_count].X = objects[object_count].XOtherPage = x;
  89.   objects[object_count].Y = objects[object_count].YOtherPage = y;
  90.   objects[object_count].Width = width;
  91.   objects[object_count].Height = height;
  92.   objects[object_count].XDir = xdir;
  93.   objects[object_count].YDir = ydir;
  94.   objects[object_count].Image = image;
  95.   objects[object_count].bg = ( BYTE * )malloc(4*width*height+20);
  96.   objects[object_count].bgOtherPage = ( BYTE * )malloc(4*width*height+20);
  97.   x_get_pbm(x,y,(unsigned)width,height,VisiblePageOffs,
  98.     objects[object_count].bg);
  99.   x_get_pbm(x,y,(unsigned)width,height,HiddenPageOffs,
  100.     objects[object_count].bgOtherPage);
  101.   object_count++;
  102. }
  103.  
  104. /* Move the specified object, bouncing at the edges of the screen and
  105.    remembering where the object was before the move for erasing next time */
  106. void MoveObject(AnimatedObject * ObjectToMove) {
  107.    int X, Y;
  108.    BYTE *cptr;
  109.    X = ObjectToMove->X + ObjectToMove->XDir;
  110.    Y = ObjectToMove->Y + ObjectToMove->YDir;
  111.    if ((X < 0) || (X > (ScrnLogicalPixelWidth-((ObjectToMove->Width)<<2)))) {
  112.       ObjectToMove->XDir = -ObjectToMove->XDir;
  113.       X = ObjectToMove->X + ObjectToMove->XDir;
  114.    }
  115.    if ((Y < 0) || (Y > (ScrnLogicalHeight-ObjectToMove->Height))) {
  116.       ObjectToMove->YDir = -ObjectToMove->YDir;
  117.       Y = ObjectToMove->Y + ObjectToMove->YDir;
  118.    }
  119.    /* Remember previous location for erasing purposes */
  120.    ObjectToMove->XOtherPage = ObjectToMove->X;
  121.    ObjectToMove->YOtherPage = ObjectToMove->Y;
  122.    ObjectToMove->X = X; /* set new location */
  123.    ObjectToMove->Y = Y;
  124.    cptr = ObjectToMove->bg;
  125.    ObjectToMove->bg = ObjectToMove->bgOtherPage;
  126.    ObjectToMove->bgOtherPage = cptr;
  127. }
  128.  
  129. void animate(void){
  130.  int i;
  131.  for(i=object_count-1;i>=0;i--){
  132.   x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage,
  133.      HiddenPageOffs,objects[i].bgOtherPage);
  134.  }
  135.  for(i=0;i<object_count;i++){
  136.   MoveObject(&objects[i]);
  137.  
  138.   x_get_pbm(objects[i].X,objects[i].Y,
  139.     (unsigned)objects[i].Width,objects[i].Height,HiddenPageOffs,
  140.     objects[i].bg);
  141.   x_put_masked_pbm(objects[i].X,objects[i].Y,HiddenPageOffs,
  142.     objects[i].Image);
  143.  }
  144. }
  145.  
  146. void clear_objects(void){
  147.  int i;
  148.  for(i=object_count-1;i>=0;i--){
  149.   x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage,
  150.      HiddenPageOffs,objects[i].bgOtherPage);
  151.  }
  152. }
  153.  
  154.  
  155. void textwindow(int Margin){
  156.    int x0=0+Margin;
  157.    int y0=0+Margin;
  158.    int x1=ScrnPhysicalPixelWidth-Margin;
  159.    int y1=ScrnPhysicalHeight-Margin;
  160.    x_rect_fill(x0, y0, x1,y1,VisiblePageOffs,1);
  161.    x_line(x0,y0,x1,y0,2,VisiblePageOffs);
  162.    x_line(x0,y1,x1,y1,2,VisiblePageOffs);
  163.    x_line(x0,y0,x0,y1,2,VisiblePageOffs);
  164.    x_line(x1,y0,x1,y1,2,VisiblePageOffs);
  165.    x_line(x0+2,y0+2,x1-2,y0+2,2,VisiblePageOffs);
  166.    x_line(x0+2,y1-2,x1-2,y1-2,2,VisiblePageOffs);
  167.    x_line(x0+2,y0+2,x0+2,y1-2,2,VisiblePageOffs);
  168.    x_line(x1-2,y0+2,x1-2,y1-2,2,VisiblePageOffs);
  169.    textwindow_x=x0;
  170.    textwindow_y=y0;
  171.  
  172. }
  173.  
  174.  
  175. void wait_for_keypress(void){
  176.   x_show_mouse();
  177.   while(kbhit()) getch();
  178.   palscrolldir^=1;
  179.  
  180.   do {
  181.     x_rot_pal_struc(pal,palscrolldir);
  182.     MouseFrozen=1;
  183.     x_put_pal_struc(pal);
  184.     x_update_mouse();
  185.   } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED));
  186.   while(MouseButtonStatus==LEFT_PRESSED);
  187.   while(kbhit()) getch();
  188.  
  189. }
  190.  
  191.  
  192. void exitfunc(void){
  193.   x_mouse_remove();
  194. //  x_remove_vsync_handler();
  195.   x_text_mode();
  196.   printf("Thanks to everyone who assisted in the development of XLIB.\n");
  197.   printf("\nSpecial thanks to Matthew Mackenzie for contributing \n");
  198.   printf("lots of code, documentation and ideas.\n\n");
  199.   printf("If you make any money using this code and you're the generous\n");
  200.   printf("type please send us some, or at least a copy of your program!\n");
  201. }
  202.  
  203. int terminate(void){
  204.   exit(0);
  205.   return 0;
  206. }
  207.  
  208. void intro_1(void){
  209.   x_set_rgb(1,40,40,40); /* BG Gray */
  210.   x_set_rgb(2,63,63,0);  /* Bright Yellow  */
  211.   x_set_rgb(3,63,0,0);   /* Bright Red     */
  212.   x_set_rgb(4,0,63,0);   /* Bright Green   */
  213.   x_set_rgb(5,0,0,63);   /* Bright Blue    */
  214.   x_set_rgb(6,0,0,28);   /* Dark Blue      */
  215.   x_set_rgb(7,0,28,0);   /* Dark Green     */
  216.   x_set_rgb(8,28,0,0);   /* Dark red       */
  217.   x_set_rgb(9,0,0,38);   /* Med Blue       */
  218.  
  219.   textwindow(20);
  220.   x_set_font(1);
  221.   x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6,"     XLIB Version 6.0");
  222.   x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2,"     XLIB Version 6.0");
  223.   x_set_font(0);
  224.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"       Not the Unix version");
  225.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,2,"       Not the Unix version");
  226.  
  227.   x_printf(textwindow_x+24,168,VisiblePageOffs,6,"     Press any key to continue");
  228.   x_printf(textwindow_x+23,167,VisiblePageOffs,2,"     Press any key to continue");
  229. }
  230.  
  231. void subsequent_page(void){
  232.   x_hide_mouse();
  233.   textwindow(20);
  234.   x_set_font(1);
  235.   x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6,"     XLIB Version 6.0");
  236.   x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2,"     XLIB Version 6.0");
  237.   x_set_font(0);
  238.   x_printf(textwindow_x+24,168,VisiblePageOffs,6,"     Press any key to continue");
  239.   x_printf(textwindow_x+23,167,VisiblePageOffs,2,"     Press any key to continue");
  240. }
  241.  
  242. void load_user_fonts(void){
  243.   FILE *f;
  244.   f=fopen("var6x8.fnt","rb");
  245.   /* read char by char as fread wont read to pointers in small model */
  246.   { int i; char c;
  247.     for (i=0;i<256*8+4;i++){
  248.       fread(&c,1,1,f);
  249.       *(userfnt1+i)=c;
  250.     }
  251.   }
  252.  
  253.   fclose(f);
  254.  
  255.   x_register_userfont(userfnt1);
  256.  
  257. }
  258.  
  259. int random(
  260.     int iLimit
  261. )
  262. {
  263.   return ( rand() % iLimit );
  264. }
  265.  
  266.  
  267. void main(){
  268.   int  i, j, xinc, yinc, Margin;
  269.   char ch;
  270.   WORD curr_x=0, curr_y=0;
  271.  
  272.   pal    = (BYTE *) malloc(256*3);
  273.   pal2   = (BYTE *) malloc(256*3);
  274.   userfnt1 = (BYTE *) malloc(256*16+4);
  275.  
  276.  
  277.   /* INITIALIZE XLIB */
  278.  
  279.   /* we set up Mode X 360x200x256 with a logical width of ~ 500 */
  280.   /* pixels; we actually get 496 due to the fact that the width */
  281.   /* must be divisible by 8                                     */
  282.  
  283.   x_text_mode(); /* make sure VGA is in color mode, if possible */
  284.   x_set_mode(X_MODE_360x200,500);           /* actually is set to 496      */
  285. //  x_install_vsync_handler(2);
  286.   x_set_splitscreen(ScrnPhysicalHeight-60); /* split screen 60 pixels high */
  287.   x_set_doublebuffer(220);
  288.   x_text_init();
  289.   x_hide_splitscreen();
  290.   x_mouse_init();
  291.   MouseColor=2;
  292.   atexit(exitfunc);
  293.  
  294.   /* DRAW BACKGROUND LINES */
  295.  
  296.   for(j=0;j<ScrnPhysicalHeight;j++){
  297.    x_line(0,j,ScrnLogicalPixelWidth,j,16+(j%239),VisiblePageOffs);
  298.   }
  299.  
  300. //  ctrlbrk(terminate);
  301.   x_get_pal_struc(pal, 240,16);
  302.   load_user_fonts();
  303.  
  304.   intro_1();
  305.   x_set_font(2);
  306.   x_hide_mouse();
  307.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Hi, folks. This is yet another FREEWARE Mode X");
  308.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " graphics library. It is by no means complete,");
  309.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " but I believe it contains a rich enough set of");
  310.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " functions to achieve its design goal - to be");
  311.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " a game development oriented library for");
  312.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Borland TC/BC/BC++ and TASM programmers.");
  313.  
  314.   x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, "   This library comes with TASM and C sources.");
  315.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " It was inspired by the DDJ Graphics column and");
  316.   x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " many INTERNET and USENET authors who, unlike the");
  317.   x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " majority of programmers (you know who you are!),");
  318.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " willingly share their code and ideas with others.");
  319.  
  320.   x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, "   I can't afford, nor do I want, to copyright");
  321.   x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " this code - but if you use it, some credit would ");
  322.   x_printf(textwindow_x+5,50+104,VisiblePageOffs,9," be appreciated. ");
  323.  
  324.   wait_for_keypress();
  325.  
  326.   subsequent_page();
  327.   x_set_font(0);
  328.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"Supported 256 colour resolutions.");
  329.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"Supported 256 colour resolutions.");
  330.   x_set_font(2);
  331.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " 320x200   Standard for games       ~ 4 pages");
  332.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " 320x240   DDJ Mode X square pixels ~ 3.5 pages");
  333.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " 360x200   My favourite for games   ~ 3 pages  ");
  334.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " 360x240                            ~ 2.8 pages");
  335.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " 320x400                            ~ 2 pages  ");
  336.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " 320x480   All subsequent modes support");
  337.   x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, " 360x400     less than two pages.");
  338.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " 360x480");
  339.   x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " 376x282,360x360,376x308,376x564,256x200,256x240");
  340.   x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " Phew! and they'll run on all VGA cards and ");
  341.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " monitors (some of the weird ones are best suited");
  342.   x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, " to monitors with both vert & horiz adjustments)");
  343.   x_printf(textwindow_x+5,50+98,VisiblePageOffs,2, "  ");
  344.   x_printf(textwindow_x+5,50+106,VisiblePageOffs,2," Overkill? Maybe!! ");
  345.  
  346.  
  347.   wait_for_keypress();
  348.  
  349.   subsequent_page();
  350.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"      Text display functions.");
  351.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"      Text display functions.");
  352.   x_set_font(2);
  353.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Several text printing functions are provided.");
  354.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " They support the VGA ROM 8x14 and 8x8 fonts as");
  355.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " well as user-defined fonts (like this 6x8 font).");
  356.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " Furthermore, a function similar to printf is");
  357.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " included which provides formatted text output.");
  358.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " User defined fonts may be proportionally spaced");
  359.   x_printf(textwindow_x+5,50+58,VisiblePageOffs,9, " but have a maximum width of 8 pixels.");
  360.  
  361.  
  362.   wait_for_keypress();
  363.  
  364.   subsequent_page();
  365.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    Advanced screen functions.");
  366.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    Advanced screen functions.");
  367.   x_set_font(2);
  368.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   The library supports virtual screens larger");
  369.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " than the physical screen, panning of such");
  370.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " screens, and a split screen option.");
  371.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, "   These functions can be used together or");
  372.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " in isolation, and in the lower resolutions");
  373.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " double buffering can also be accomplished.");
  374.  
  375.   x_rect_fill(0, 0, ScrnPhysicalPixelWidth,60,SplitScrnOffs,5);
  376.   x_line(0,0,ScrnPhysicalPixelWidth,0,2,SplitScrnOffs);
  377.   x_set_font(1);
  378.   x_printf(10,10,SplitScrnOffs,2, " This is a split screen, tops for scores.");
  379.   x_set_font(0);
  380.   for (i=ScrnPhysicalHeight;i>ScrnPhysicalHeight-60;i--){
  381.     x_adjust_splitscreen(i);
  382.   }
  383.   x_printf(10,25,SplitScrnOffs,2, " Even better for scrolling games etc.");
  384.  
  385.   x_cp_vid_rect(0,0,ScrnLogicalPixelWidth,ScrnLogicalHeight,0,0,
  386.         VisiblePageOffs,HiddenPageOffs,
  387.         ScrnLogicalPixelWidth,ScrnLogicalPixelWidth);
  388.  
  389.  
  390.   x_show_mouse();
  391.   wait_for_keypress();
  392.  
  393.   curr_x=curr_y=0;
  394.  
  395.  
  396.   init_object(60,90,4, 12, -1, 1, bm2 );
  397.   init_object(30,30,4, 12, 1, 1, bm );
  398.   init_object(80,120,4, 12, 2, 1, bm );
  399.   init_object(300,200,4, 12, 1, -2, bm );
  400.   init_object(360,30,4, 12, -1, -1, bm );
  401.   init_object(360,10,4, 12, -2, 2, bm );
  402.  
  403.   x_hide_mouse();
  404.  
  405.   while (!kbhit()&& !(MouseButtonStatus==LEFT_PRESSED)){
  406.     animate();
  407.     if (objects[0].X>=curr_x+ScrnPhysicalPixelWidth-32 &&
  408.     curr_x < MaxScrollX) curr_x++;
  409.     else if (objects[0].X < curr_x+16 && curr_x > 0) curr_x--;
  410.     if (objects[0].Y>=curr_y+ScrnPhysicalHeight-92 &&
  411.        curr_y < MaxScrollY) curr_y++;
  412.     else if (objects[0].Y < curr_y+16 && curr_y > 0) curr_y--;
  413.     x_page_flip(curr_x,curr_y);
  414.     while(StartAddressFlag);
  415.   }
  416.   while(MouseButtonStatus==LEFT_PRESSED);
  417.   while(kbhit()) getch();
  418.  
  419.   clear_objects();
  420.   x_page_flip(curr_x,curr_y);
  421.   while(StartAddressFlag);
  422.  
  423.  
  424.   x_set_start_addr(0,0);
  425.  
  426.  
  427.   for (j=0;j<4;j++){
  428.     x_hide_splitscreen();
  429.     delay(100);
  430.     x_show_splitscreen();
  431.     delay(100);
  432.   }
  433.  
  434.  
  435.   for (i=ScrnPhysicalHeight-60;i<=ScrnPhysicalHeight;i++){
  436.     x_adjust_splitscreen(i);
  437.   }
  438.  
  439.   x_hide_mouse();
  440.   subsequent_page();
  441.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"        Palette functions.");
  442.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"        Palette functions.");
  443.   x_set_font(2);
  444.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   A number of palette manipulation functions");
  445.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " are provided. You have already seen some of");
  446.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " them in action. Another common operation is");
  447.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " palette fading.                     ");
  448.  
  449.   i=0;
  450.   ch=255;
  451.   while (x_cpcontrast_pal_struc(pal, pal2,ch-=2)){
  452.     x_put_pal_struc(pal2);
  453.     x_rot_pal_struc(pal,palscrolldir);
  454.     i++;
  455.   };
  456.   for (j=0;j<i;j++){
  457.     x_cpcontrast_pal_struc(pal, pal2,ch+=2);
  458.     x_put_pal_struc(pal2);
  459.     x_rot_pal_struc(pal,palscrolldir);
  460.   };
  461.   wait_for_keypress();
  462.  
  463.   subsequent_page();
  464.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 3.0 Functions!");
  465.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 3.0 Functions!");
  466.   x_set_font(2);
  467.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  468.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - RLE data compression");
  469.   x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, "  - FAST compiled masked bitmaps");
  470.   x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, "  - Hardware detection");
  471.  
  472.   x_show_mouse();
  473.   wait_for_keypress();
  474.  
  475.   x_hide_mouse();
  476.   for (i = 0; i < 150; i++) {
  477.       x_circle(0, 0, i, 181 - i, VisiblePageOffs);
  478.       x_circle(360 - i, 0, i, i + 30, VisiblePageOffs);
  479.       x_circle(0, 200 - i, i, i + 30, VisiblePageOffs);
  480.       x_circle(360 - i, 200 - i, i, 181 - i, VisiblePageOffs);
  481.   }
  482.   for (i = 0; i < 100; i++)
  483.     x_filled_circle(80 + i, i, 201 - (i << 1), 30+i, VisiblePageOffs);
  484.   x_show_mouse();
  485.   wait_for_keypress();
  486.  
  487.   subsequent_page();
  488.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 4.0 Functions!");
  489.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 4.0 Functions!");
  490.   x_set_font(2);
  491.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  492.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - FAST VRAM-based masked bitmaps, including");
  493.   x_printf(textwindow_x+5,50+18,VisiblePageOffs,9, "      support for clipping regions");
  494.   x_printf(textwindow_x+5,50+28,VisiblePageOffs,9, "  - Faster, smaller compiled bitmaps");
  495.   x_printf(textwindow_x+5,50+38,VisiblePageOffs,9, "  - Improved planar bitmap performance and");
  496.   x_printf(textwindow_x+5,50+46,VisiblePageOffs,9, "      additional support for clipping");
  497.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, "  - mouse module");
  498.   x_printf(textwindow_x+5,50+66,VisiblePageOffs,9, "  - Detection of math co-processor and mouse");
  499.   x_printf(textwindow_x+5,50+76,VisiblePageOffs,9, "  - Bezier curve module");
  500.   x_printf(textwindow_x+5,50+86,VisiblePageOffs,9, "  - Four new resolutions, including one with");
  501.   x_printf(textwindow_x+5,50+94,VisiblePageOffs,9, "      square pixels (376x282)");
  502.   x_printf(textwindow_x+5,50+104,VisiblePageOffs,9, "  - More bug fixes");
  503.  
  504.   wait_for_keypress();
  505.  
  506.   subsequent_page();
  507.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 5.0 Functions!");
  508.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 5.0 Functions!");
  509.   x_set_font(2);
  510.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " - *FAST* filled and clipped triangles ideal for");
  511.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "   3D work. Thanks to S. Dollins for the code.");
  512.   x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Filled and clipped polygons, C++ Compatible");
  513.   x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - header files, and of course bug fixes!");
  514.  
  515.   x_show_mouse();
  516.   wait_for_keypress();
  517.  
  518.   subsequent_page();
  519.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 6.0 Functions!");
  520.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 6.0 Functions!");
  521.   x_set_font(2);
  522.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " - Fast flood filling functions ");
  523.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " - New pbm flipping put functions.");
  524.   x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Timer synchronized vertical retrace");
  525.   x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - Tripple buffering extensions");
  526.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Checkout demo 9 and 10 for previews");
  527.   
  528.  
  529.  
  530.   x_show_mouse();
  531.   wait_for_keypress();
  532.  
  533.  
  534. //  randomize();
  535.   x_hide_mouse();
  536.   while(kbhit()) getch();
  537.   palscrolldir^=1;
  538.   do {
  539.     int x0,x1,x2,y0,y1,y2,i;
  540.     i=random(256);
  541.     x0=random(ScrnLogicalPixelWidth);
  542.     x1=random(ScrnLogicalPixelWidth);
  543.     x2=random(ScrnLogicalPixelWidth);
  544.     y0=random(ScrnPhysicalHeight);
  545.     y1=random(ScrnPhysicalHeight);
  546.     y2=random(ScrnPhysicalHeight);
  547. //_triangle(x0,y0,x1,y1,x2,y2,i,VisiblePageOffs);
  548.     x_rect_fill( x0, y0, x1, y1, VisiblePageOffs, i );
  549.   } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED));
  550.   while(MouseButtonStatus==LEFT_PRESSED);
  551.   while(kbhit()) getch();
  552.   x_show_mouse();
  553.  
  554.   subsequent_page();
  555.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"             PLEASE...");
  556.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"             PLEASE...");
  557.   x_set_font(2);
  558.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Please mention my name in programs that use XLIB");
  559.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " just to make me feel it was worth the effort.");
  560.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " If you have any bug to report please feel free to");
  561.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " mail me a message. Any hints, suggestions and");
  562.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " contributions are welcome and encouraged.");
  563.   x_printf(textwindow_x+5,50+52,VisiblePageOffs,9, " I have contributed this code to the public domain.");
  564.   x_printf(textwindow_x+5,50+60,VisiblePageOffs,9, "    Please respect my wishes and leave it there.");
  565.  
  566.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, "   Finally, I hope you all find this stuff useful,");
  567.   x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " Themie Gouthas - EGG@DSTOS3.DSTO.GOV.AU");
  568.  
  569.   wait_for_keypress();
  570.  
  571.   x_hide_mouse();
  572.  
  573.   x_shift_rect (27, 27, 360-27, 177, 27, 23, VisiblePageOffs);
  574.   x_rect_fill(25, 173, 335, 176, VisiblePageOffs, 1);
  575.   for (i = 0; i < 50; i++) {
  576.     x_shift_rect (27, 26, 360-27, 177 - (i * 3), 27, 23, VisiblePageOffs);
  577.   }
  578. }
  579.  
  580.  
  581.